import com.google.appengine.api.datastore.*
import groovyx.gaelyk.datastore.Entity
import groovyx.gaelyk.datastore.Key
import groovyx.gaelyk.datastore.Unindexed
import groovyx.gaelyk.datastore.Ignore

import groovy.time.*

@Entity(unindexed=false)
class Report {
	@Key String reportID
	String reportTitle
	@Unindexed String reportText
	int priorityLevel
	int credibilityLevel
	int validationStatus
	int clearanceLevel
	int reportCategoryID
	String reportCategoryName
	boolean reportRead
	GeoPt reportLocation
	Link reportImageLink
	Date reportTimestamp
	
	@ Ignore String getLat () {return reportLocation.getLatitude().toString() }
	@ Ignore String getLng () {return reportLocation.getLongitude().toString() }
 
	@Ignore String getTimeSince (){

		if (reportTimestamp!=null){
			//def start = Date.parse("yyy-MM-dd'T'HH:mm:ss.SSS",reportTimestamp );

			TimeDuration duration = TimeCategory.minus(new Date(), reportTimestamp)
			return "Days: ${duration.days}, Hours: ${duration.hours} Minutes: ${duration.minutes}"
		}
		else
			return "cannot calculate time since"
	}
	
	@Ignore String linkVal (){
		return reportImageLink.getValue()
	}	
}



